package com.eelye.util.winui.manager;

import com.eelye.util.winui.window.Process;
import com.eelye.util.winui.window.Window;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class WindowManagerTest_UT {

    @Nested
    class findTopWindow {

        @Test
        void 测试不存在的类名_应该找不到() throws Exception {
            Process p = ProcessManager.launchProcess("C:\\Windows\\system32\\mstsc.exe");

            String clsName = "Afx:dfasdfsfd";
            String text = "远程桌面连接";

            Window treeView = WindowManager.findTopWindow(clsName, false, text, false, 5_000);

            ProcessManager.terminateProcess(p);

            assertNull(treeView);
        }

        @Test
        void 测试不存在的text_应该找不到() throws Exception {
            Process p = ProcessManager.launchProcess("C:\\Windows\\system32\\mstsc.exe");

            String clsName = "#32770 (Dialog)";
            String text = "远程桌面连接77";

            Window treeView = WindowManager.findTopWindow(clsName, false, text, false, 5_000);

            ProcessManager.terminateProcess(p);

            assertNull(treeView);
        }

        @Test
        void 测试存在的类名和存在的text_应该找到并且hwnd不为空() throws Exception {
            Process p = ProcessManager.launchProcess("C:\\Windows\\system32\\mstsc.exe");

            String clsName = "#32770";
            String text = "远程桌面连接";

            Window treeView = WindowManager.findTopWindow(clsName, false, text, false, 5_000);

            ProcessManager.terminateProcess(p);

            assertNotNull(treeView);
            assertNotNull(treeView.getHWnd());
        }
    }
}